<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/12/3
 * Time: 14:34
 */
namespace app\autoreply\controller;

use app\common\config\autoreply_config;
use app\common\model\Autoreply;
use app\common\model\AutoreplyContent;
use app\common\model\AutoreplyKey;
use think\facade\Request;
use app\admin\controller\AdminBase;

class Delete extends AdminBase
{
    private $autoreply_type;

    public function __call($action = "", $params = array())
    {
        $this->autoreply_type = autoreply_config::$autoreply_type;

        if ($action != 3) {
            return ['info' => '操作地址有误'];
        }

        $id   = Request::param('id', 0);
        if (!$id) {
            return ['info' => '请选择要删除的关键词'];
        }
        $autoreply_info = _uri('autoreply', ['id' => $id]);
        if (!$autoreply_info || $autoreply_info['company_id'] != $this->company_id) {
            return ['info' => '该关键词不存在'];
        }

        Autoreply::destroy($id);
        AutoreplyKey::where(['autoreply_id'=>$id])->delete();
        AutoreplyContent::where(['autoreply_id'=>$id])->delete();

        return ['info' => 'ok'];
    }
}